Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-joint

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-joint

Perform data joins with any type of JS objects

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47K
increased by6.73%
Maintainers
1
Weekly downloads
 
Created
Source

data-joint

NPM package Build Size NPM Downloads

Library to perform data joins with any type of JavaScript objects. Useful in digest cycles where it's important to minimize changes to a view for performance reasons, such as DOM manipulation. The module binds data points to objects via hidden attributes, and performs diffing comparisons across multiple iterations to ensure objects are not created or removed unnecessarily, thus keeping view changes to a minimum.

Quick start

import dataJoint from 'data-joint';

or using a script tag

<script src="//unpkg.com/data-joint"></script>

then

const myData = [{ id: 0, val: 2 }, { id: 1, val: 4 }, { id: 2, val: 7 }];
const myView = new Set();

dataJoint(myData, [...myView], 
    obj => myView.add(obj), // append obj
    obj => myView.delete(obj), // remove obj
    {
        createObj: () => ({}),
        updateObj: (obj, d) => { obj.double = d.val * 2 },
        exitObj: obj => { obj.double = 0 },
        idAccessor: d => d.id
    }
);

API reference

Syntax

dataJoint(data, existingObjs, appendObjFn, removeObjFn, [{options}]);

Arguments

data: An array of data points. Each point should be an object that supports attribute binding.

existingObjs: An array of view objects to join the data with.

appendObjFn: The method to add a new object to the view. The object is passed as single argument: obj => { ... }.

removeObjFn: The method to remove an existing object from the view. The object is passed as single argument: obj => { ... }.

Options

An optional configuration object supporting the additional arguments:

OptionDescriptionDefault
createObjThe method to create an entering view object for a new data point that does not have a corresponding object. The data point is passed as single argument: d => { ... }. The method should return a new object.d => ({})
updateObjThe method to update an existing bound object with new data. The object and the data point are passed as arguments: (obj, d) => { ... }. This method is also called for entering objects after createObj.(obj, d) => {}
exitObjThe method to handle exiting objects which no longer have a corresponding data point. The unbound object is passed as single argument: obj => { ... }. This method is called prior to removing it from the view via removeObjectFn.obj => {}
objBindAttrThe attribute name used to bind data points to view objects. Each data point passed through the digest will be added this attribute, and it will be used for diffing across multiple iterations.__obj
dataBindAttrThe attribute name used to bind view objects to data points. Each object maintained by the digest will be added this attribute, and it will be used for diffing across multiple iterations.__data
idAccessorA data point accessor function to extract the point unique identifier. This is used for comparing data points across multiple iterations. If no idAccessor is supplied, the data point object reference will be used instead for comparisons. The data point is passed as single argument: d => {...}. The method should return a unique identifier.undefined
purgeA boolean value. If set to true it will bypass the data diffing, resulting in all the existingObjs being marked for removal and new objects created for the all the items in the input data.false

Keywords

FAQs

Package last updated on 08 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc